package com.zjq.smartdevice.utils;

import com.zjq.smartdevice.pojo.SysUserInfo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @User zhangjiaqi
 * @Project project
 * @Package com.zjq.smartdevice.utils
 * @Date 2022/3/17 15:54
 */
public class SecurityUtils {
    public static SysUserInfo getLoginUser() {

        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            return (SysUserInfo) request.getSession().getAttribute("user");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public static SysUserInfo getLoginUserWithTest() {
        SysUserInfo sysUserInfo = new SysUserInfo();
        sysUserInfo.setUsername("zhangsan");
        return sysUserInfo;
    }
}
